<?php
/* @var $this yii\web\View */

$this->title = '计算机';
?>

<style>
  .alert_search_input {
    width: 80px;
    height: 30px;
    float: right;
    margin-right: 10px;
  }

  [treecontrol] li {
    line-height: 30px;
  }

  [treecontrol] ul {}

  [treecontrol] li .tree-label {
    cursor: pointer;
    display: inline-block;
    width: 100%;
  }
</style>
<!-- Main content -->
<section class="content" ng-app="myApp">
  <div class="row">
    <div class="col-md-12">
      <div class="nav-tabs-custom" style="margin-bottom: 0px">
        <ul class="nav nav-tabs" style="margin-bottom:-1px;">
          <li class="active"><a href="#protect" data-toggle="tab" aria-expanded="true">受保护的计算机</a></li>
          <li><a href="#quarantine" data-toggle="tab" aria-expanded="false">被隔离的计算机</a></li>
        </ul>

        <div class="tab-content" style="padding-top:0px;border-bottom:0px; ">
          <div class="tab-pane active" id="protect" ng-controller="protectCtrl">
            <div class="row margin">
              <div class="form-group col-md-2">
                <label>计算机名</label>
                <input type="text" class="form-control" ng-model="searchData.ComputerName"
                  ng-change="searchDataChange('ComputerName')" ng-keyup="myKeyup($event)">
              </div>
              <!-- <div class="form-group col-md-2">
                                <label>配置文件</label>
                                <select class="form-control" ng-model="searchData.ProfileVersion" ng-change="searchDataChange('ProfileVersion')">
                                    <option value="*">所有</option>
                                    <?php foreach ($ProfileVersionList as $key => $value): ?>
                                    <option value="<?=$value->ProfileVersion?>">
                                        <?=$value->ProfileVersion?>
                                    </option>
                                    <?php endforeach?>
                                </select>
                            </div> -->
              <div class="form-group col-md-2">
                <label>状态</label>
                <select class="form-control" ng-model="searchData.status" ng-change="searchDataChange('status')">
                  <option value="*">所有</option>
                  <option value="1">在线</option>
                  <option value="2">断线</option>
                  <option value="0">卸载</option>
                </select>
              </div>
              <div class="form-group col-md-2">
                <label>IP</label>
                <input type="text" class="form-control" ng-model="searchData.IP">
              </div>
              <div class="form-group col-md-2">
                <label>MAC地址</label>
                <input type="text" class="form-control" ng-model="searchData.MacAddresses">
              </div>

              <div class="form-group col-md-2">
                <label>操作系统</label>
                <input type="text" class="form-control" ng-model="searchData.OSType">
              </div>
              <div class="form-group col-md-2">
                <label>组</label>
                <input ng-model="grounpSelectInput" name="" class="form-control" ng-click="searchGroups()"
                  style="cursor: default;" />
              </div>
              <div class="form-group col-md-2">
                <label>Sensor版本</label>
                <select class="form-control" ng-model="searchData.SensorVersion"
                  ng-change="searchDataChange('SensorVersion')">
                  <option value="*">所有</option>
                  <?php foreach ($SensorVersionList as $key => $value): ?>
                  <option value="<?=$value->SensorVersion?>">
                    <?=$value->SensorVersion?>
                  </option>
                  <?php endforeach?>
                </select>
              </div>
              <div class="form-group col-md-2">
                <label>硬件信息</label>
                <input type="text" class="form-control" ng-model="searchData.Hardware">
              </div>
              <div class="form-group col-md-2">
                <label>软件信息</label>
                <input type="text" class="form-control" ng-model="searchData.software">
              </div>
              <div class="form-group col-md-2">
                <label>断线时间</label>
                <select class="form-control" ng-model="searchData.updated_at">
                  <option value="*">所有</option>
                  <option value="1">1天前</option>
                  <option value="3">3天前</option>
                  <option value="7">7天前</option>
                  <option value="30">30天前</option>
                </select>
              </div>
              <div class="form-group col-md-2">
                <label style="width: 100%;">&nbsp;</label>
                <button class="form-control btn btn-success" style="max-width: 80px;"
                  ng-click="search()">搜&nbsp;&nbsp;索</button>
              </div>
            </div>
            <div class="row margin">
              <?php if (Yii::$app->user->identity->role == 'admin') {?>
              <div class="btn-group" style="width:100%">
                <!-- <button type="button" ng-click="sendUpdateProfile()" class="btn btn-default" ng-class="sensorsuccessList.length  && sensorDangerList.length == 0 ? '' : 'disabled'"  ng-disabled="!sensorsuccessList.length || sensorDangerList.length" >赋予计算机配置文件</button> -->
                <button type="button" ng-click="addGroups()" class="btn btn-default"
                  ng-class="sensorsuccessList.length  && sensorDangerList.length == 0 ? '' : 'disabled'"
                  ng-disabled="!sensorsuccessList.length || sensorDangerList.length">加入计算机组</button>
                <button type="button" ng-click="sendUpdate()" class="btn btn-default"
                  ng-class="sensorsuccessList.length  && sensorDangerList.length == 0 ? '' : 'disabled'"
                  ng-disabled="!sensorsuccessList.length || sensorDangerList.length">升级Sensor</button>
                <button type="button" ng-click="sendBase('UNINIT')" class="btn btn-default"
                  ng-class="sensorsuccessList.length  && sensorDangerList.length == 0 ? '' : 'disabled'"
                  ng-disabled="!sensorsuccessList.length || sensorDangerList.length">卸载Sensor</button>
                <button type="button" ng-click="sendDelete()" class="btn btn-default"
                  ng-class="sensorDangerList.length  && sensorsuccessList.length == 0 ? '' : 'disabled'"
                  ng-disabled="!sensorDangerList.length || sensorsuccessList.length">删除计算机</button>
                  <button class="form-control btn " style="max-width: 80px;border-color:#d2d6de;position:absolute;right:33px;"
                  ng-click="showConfigColumn()">配置列</button>
              </div>
              <?php }?>
              <style type="text/css">
                .list-group-item:first-child,
                .list-group-item:last-child {
                  border-radius: 0px;
                }
              </style>
              <div id="hide_box" style="display: none;">
                <div id="update_list"></div>
                <div id="profile_list"></div>
                <div id="groupTree">
                  <div class="search_box" style="display:flex; padding-left:20px">
                    <input type="text" id="GroupSearchData" ng-model="searchGroupTreeInput" class="form-control">
                    <button id="searchBtn" ng-click="searchGroupTree()" class="btn btn-md btn-default">搜索</button>
                  </div>
                  <div treecontrol class="tree-classic" tree-model="dataForTheTree" options="treeOptions"
                    on-selection="showSelected(node,selected)" selected-node="node1">
                    {{node.text}}
                  </div>
                  <!-- <div id="groupTreeview"></div> -->
                </div>
                <!-- 添加弹窗 -->
                <div id="addgroupTree">
                  <div class="search_box" style="display:flex; padding-left:20px">
                    <input type="text" ng-model="searchAddGroupTreeInput" class="form-control">
                    <button id="searchBtn" ng-click="searchAddGroupTree()" class="btn btn-md btn-default">搜索</button>
                  </div>
                  <div treecontrol class="tree-classic" tree-model="dataAddForTheTree" options="treeOptions"
                    on-selection="showAddSelected(node,selected)" selected-node="node12">
                    {{node.text}}
                  </div>
                </div>
                <!-- 硬件信息 -->
                <table id="showHardwareInfo" class="table table-hover selectSensor">
                  <thead>
                    <tr>
                      <th width="80">硬件</th>
                      <th>描述</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr ng-repeat="item in HardwareInfoList">
                      <td ng-bind="item.HardwareName"></td>
                      <td ng-bind="item.HardwareInfo"></td>
                    </tr>
                  </tbody>
                </table>
                <!-- 软件信息 -->
                <table id="showsoftwareInfo" class="table table-hover selectSensor">
                  <thead>
                    <tr>
                      <th >软件名称</th>
                      <th>软件版本</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr ng-repeat="item in softwareInfoList">
                      <td ng-bind="item.DisplayName"></td>
                      <td ng-bind="item.DisplayVersion"></td>
                    </tr>
                  </tbody>
                </table>
                <div id="configColumn">
                    <p > <input type="checkbox" name="1" ng-model="config.ComputerName" ng-disabled='true' checked> 计算机名</p>
                    <p> <input type="checkbox" name="2"  ng-model="config.status" ng-disabled='true'checked> 状态</p>
                    <p> <input type="checkbox" name="3" ng-model="config.IP" ng-disabled='true' checked> IP</p>
                    <p> <input type="checkbox" name="4" ng-model="config.MacAddresses"  checked> MAC地址</p>
                    <p> <input type="checkbox" name="5" ng-model="config.OSType" checked> 操作系统</p>
                    <p><input type="checkbox" name="6" ng-model="config.group"  checked>  组</p>
                    <p> <input type="checkbox" name="7" ng-model="config.SensorVersion"  checked> Sensor版本</p>
                    <p> <input type="checkbox" name="8" ng-model="config.hardware"  checked> 硬件信息</p>
                    <p> <input type="checkbox" name="9" ng-model="config.software"  checked> 软件信息</p>
                    <p> <input type="checkbox" name="0" ng-model="config.updated_at"  checked> 断线时间</p>
                    <p> <input type="checkbox" name="11" ng-model="config.created_at"  checked> 受保护起始时间</p>
                </div>
              </div>

              <div class="row margin">

                <table class="table table-hover ng-cloak" style="table-layout:fixed;">
                  <tr>
                    <th width="30"><input type="checkbox" ng-checked="SensorIDList.length == pages.data.length"
                        ng-click="selectAll()" ng-show="pages.data.length > 0"></th>
                    <th style="word-break:break-all;min-width:180px">计算机名</th>
                    <th min-width="60">状态</th>
                    <th min-width="110">IP</th>
                    <th style="word-break:break-all;min-width:200px" ng-if="configCopy.MacAddresses">MAC地址</th>
                    <th ng-if="configCopy.OSType">操作系统</th>
                    <th ng-if="configCopy.group">组</th>
                    <th ng-if="configCopy.SensorVersion">Sensor版本</th>
                    <th ng-if="configCopy.hardware">硬件信息</th>
                    <th ng-if="configCopy.software">软件信息</th>
                    <th ng-if="configCopy.updated_at">断线时间</th>
                    <th ng-if="configCopy.created_at">受保护起始时间</th>
                    <!-- <th ng-if="rsqType=='ProfileVersion'">配置文件</th> -->
                    <!-- <th ng-if="rsqType=='group'">组</th> -->
                    <!-- <th ng-if="rsqType=='SensorVersion'">Sensor版本</th> -->
                  </tr>
                  <!--ng-disabled="(sensor.status != 1)"-->

                  <tr style="cursor: pointer;" ng-repeat="sensor in pages.data" ng-click="detail(sensor.SensorID)">
                    <td><input type="checkbox" ng-checked="SensorIDList.indexOf(sensor.SensorID) != -1"
                        ng-click="selectOne(sensor,$event)" ng-hide="sensor.status == 2"></td>
                    <td  style="word-break:break-all" ng-class="sensor.isolate == 1 ? 'text-red' : ''" title="{{sensor.SensorID}}">
                      <i class="ico fa fa-laptop"></i>
                      <span ng-bind="sensor.ComputerName"></span>
                    </td>
                    <td>
                      <span class="label label-{{status_str[sensor.status].css}}"
                        ng-bind="status_str[sensor.status].label" ng-if="sensor.work != 1"></span>
                      <span class="label label-warning" ng-if="sensor.work == 1">请等待...</span>
                    </td>
                    <td ng-bind="sensor.IP"></td>
                    <td  ng-if="configCopy.MacAddresses" ng-bind="sensor.MacAddresses" style="word-break:break-all;min-width:200px"></td>
                    <td  ng-if="configCopy.OSType" ng-bind="sensor.OSTypeShort"></td>
                    <td  ng-if="configCopy.group" ng-bind="sensor.group"></td>
                    <td  ng-if="configCopy.SensorVersion" ng-bind="sensor.SensorVersion"></td>
                    <td  ng-if="configCopy.hardware">
                      <!-- <div ng-if="postData.Hardware&&postData.Hardware !='*'"> -->
                        <a
                          ng-click="ShowDetail(sensor.hardware,'hardware');$event.stopPropagation();">{{sensor.hardwareShort}}</a>
                      <!-- </div> -->
                    </td>
                    <td  ng-if="configCopy.software">
                        <!-- <div ng-if="postData.software&&postData.software !='*'"> -->
                        <a
                          ng-click="ShowDetail(sensor.data,'software');$event.stopPropagation();">{{sensor.Softwareshort}}</a>
                      <!-- </div> -->

                    </td>
                    <td  ng-if="configCopy.updated_at" >
                      <span ng-if="sensor.updated_at!=0">{{sensor.updated_at*1000 | date:'yyyy-MM-dd HH:mm'}}</span>
                      <span ng-if="sensor.updated_at==0"></span>
                    </td>
                    <td  ng-if="configCopy.created_at" ng-bind="sensor.created_at*1000 | date:'yyyy-MM-dd HH:mm'"></td>
                    <!-- <td ng-if="rsqType=='ProfileVersion'" ng-bind="sensor.ProfileVersion"></td>
                    <td ng-if="rsqType=='group'" ng-bind="groupText"></td>
                    <td ng-if="rsqType=='SensorVersion'" ng-bind="sensor.SensorVersion"></td> -->
                  </tr>
                </table>

                <!-- angularjs分页 -->
                <div style="border-top: 1px solid #f4f4f4;padding: 10px;">
                  <span>共<span ng-bind="pages.count"></span>台计算机</span>
                  <!-- angularjs分页 -->
                  <ul class="pagination pagination-sm no-margin pull-right ng-cloak">
                    <li><a href="javascript:void(0);" ng-click="getPageClick(pages.pageNow-1)"
                        ng-if="pages.pageNow>1">上一页</a></li>
                    <li><a href="javascript:void(0);" ng-click="getPageClick(1)" ng-if="pages.pageNow>1">1</a></li>
                    <li><a href="javascript:void(0);" ng-if="pages.pageNow>4">...</a></li>

                    <li><a href="javascript:void(0);" ng-click="getPageClick(pages.pageNow-2)" ng-bind="pages.pageNow-2"
                        ng-if="pages.pageNow>3"></a></li>
                    <li><a href="javascript:void(0);" ng-click="getPageClick(pages.pageNow-1)" ng-bind="pages.pageNow-1"
                        ng-if="pages.pageNow>2"></a></li>

                    <li class="active"><a href="javascript:void(0);" ng-bind="pages.pageNow"></a></li>

                    <li><a href="javascript:void(0);" ng-click="getPageClick(pages.pageNow+1)" ng-bind="pages.pageNow+1"
                        ng-if="pages.pageNow<pages.maxPage-1"></a></li>
                    <li><a href="javascript:void(0);" ng-click="getPageClick(pages.pageNow+2)" ng-bind="pages.pageNow+2"
                        ng-if="pages.pageNow<pages.maxPage-2"></a></li>


                    <li><a href="javascript:void(0);" ng-if="pages.pageNow<pages.maxPage-3">...</a></li>

                    <li><a href="javascript:void(0);" ng-click="getPageClick(pages.maxPage)" ng-bind="pages.maxPage"
                        ng-if="pages.pageNow<pages.maxPage"></a></li>
                    <li><a href="javascript:void(0);" ng-click="getPageClick(pages.pageNow+1)"
                        ng-if="pages.pageNow<pages.maxPage">下一页</a></li>
                  </ul>
                  <select class="alert_search_input" ng-change="select_change()" style="background-color: #fff;"
                    ng-model="select.model" ng-options="x.num as x.type for x in select_model"></select>
                </div>
                <!-- /.angularjs分页 -->
              </div>
            </div>

          </div>
          <!-- quarantine -->
          <div class="tab-pane" id="quarantine" ng-controller="quarantineCtrl">
            <table class="table table-hover">
              <tr>
                <th>计算机名</th>
                <th>状态</th>
                <th>IP</th>
                <th>操作系统</th>
                <th>断线时间</th>
                <th>受保护起始时间</th>
              </tr>

              <tr style="cursor: pointer;" ng-repeat="sensor in pages.data" ng-click="detail(sensor.SensorID)">
                <td ng-class="sensor.isolate == 1 ? 'text-red' : ''">
                  <i class="ico fa fa-laptop"></i>
                  <span ng-bind="sensor.ComputerName"></span>
                </td>
                <td>
                  <span class="label label-{{status_str[sensor.status].css}}"
                    ng-bind="status_str[sensor.status].label"></span>
                </td>
                <td ng-bind="sensor.IP"></td>
                <td ng-bind="sensor.OSTypeShort"></td>
                <td >
                      <span ng-if="sensor.updated_at!=0">{{sensor.updated_at*1000 | date:'yyyy-MM-dd HH:mm'}}</span>
                      <span ng-if="sensor.updated_at==0"></span>
                </td>
                <td ng-bind="sensor.created_at*1000 | date:'yyyy-MM-dd HH:mm'"></td>


              </tr>

            </table>

            <!-- /.angularjs分页 -->
            <div style="border-top: 1px solid #f4f4f4;padding: 10px;">
              <span>共<span ng-bind="pages.count"></span>台计算机</span>
              <!-- angularjs分页 -->
              <ul class="pagination pagination-sm no-margin pull-right" ng-if="pages.count>0">
                <li><a href="javascript:void(0);" ng-click="getPage(pages.pageNow-1)" ng-if="pages.pageNow>1">上一页</a>
                </li>
                <li><a href="javascript:void(0);" ng-click="getPage(1)" ng-if="pages.pageNow>1">1</a></li>
                <li><a href="javascript:void(0);" ng-if="pages.pageNow>4">...</a></li>

                <li><a href="javascript:void(0);" ng-click="getPage(pages.pageNow-2)" ng-bind="pages.pageNow-2"
                    ng-if="pages.pageNow>3"></a></li>
                <li><a href="javascript:void(0);" ng-click="getPage(pages.pageNow-1)" ng-bind="pages.pageNow-1"
                    ng-if="pages.pageNow>2"></a></li>

                <li class="active"><a href="javascript:void(0);" ng-bind="pages.pageNow"></a></li>

                <li><a href="javascript:void(0);" ng-click="getPage(pages.pageNow+1)" ng-bind="pages.pageNow+1"
                    ng-if="pages.pageNow<pages.maxPage-1"></a></li>
                <li><a href="javascript:void(0);" ng-click="getPage(pages.pageNow+2)" ng-bind="pages.pageNow+2"
                    ng-if="pages.pageNow<pages.maxPage-2"></a></li>


                <li><a href="javascript:void(0);" ng-if="pages.pageNow<pages.maxPage-3">...</a></li>

                <li><a href="javascript:void(0);" ng-click="getPage(pages.maxPage)" ng-bind="pages.maxPage"
                    ng-if="pages.pageNow<pages.maxPage"></a></li>
                <li><a href="javascript:void(0);" ng-click="getPage(pages.pageNow+1)"
                    ng-if="pages.pageNow<pages.maxPage">下一页</a></li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
</section>

<div style="display: none;" id="whiteBox">
  <div id="white">
    <span></span>
    <table class="table table-hover">
      <tr>
        <th>计算机名</th>
        <th>操作系统</th>
        <th>IP</th>
        <th>白名单</th>
      </tr>

      <tr ng-repeat="SensorID in SensorIDList">
        <td ng-bind="SensorList[SensorID].ComputerName"></td>
        <td ng-bind="SensorList[SensorID].OSTypeShort"></td>
        <td ng-bind="SensorList[SensorID].IP"></td>
        <td><input ng-model="WhiteList[SensorID]" size="90"></td>
      </tr>
    </table>
  </div>
</div>
<!-- /.content -->
<script type="text/javascript">
  var SensorFileList = <?=json_encode($SensorFileList)?> ;
  var ProFileList = <?=json_encode($ProFileList)?> ;
  var GroupList = <?=json_encode($GroupList)?> ;
</script>
<script src="/js/controllers/sensor.js"></script>